/**
 * Created by zhangqingxi on 2017-04-01.
 */

$(function () {

    initUser();
    initDept('#deptId');
    initDept('#i_deptId');
    deptChange();

    initRehearsalPlanType('#typeId');

    initRehearsalLevel('#rehearsalLevelId');
    initRehearsalLevel('#i_rehearsalLevelId');
    rehearsalLevelChange();

    initRehearsalType('#rehearsalTypeId');
    initRehearsalType('#i_rehearsalTypeId');
    rehearsalTypeChange();

    initRehearsalModel('#rehearsalModelId');
    initRehearsalModel('#i_rehearsalModelId');
    rehearsalModelChange();

    initEmergencyPlan('#emergencyPlanId');
    initEmergencyPlan('#i_emergencyPlanId');
    emergencyPlanChange();

    initYesOrNo('#zoneDefense');
    initYesOrNo('#enterpriseZoneDefense');

    initUserTable();
    initUserAddButton();
    initUserRemoveButton();



   // infoOtherDisable(0);
    var $infoOther=$('#info_other');
    $infoOther.hide();
    $infoOther.form('disableValidation');

    initSaveButtonClick(modelPath+'add.shtml');

});

/**
 * 表单提交
 * @param url
 */
function initSaveButtonClick(url) {

    $('#btn_save').on('click', function () {

        var index = layer.confirm('是否确定保存？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $('#submit_form').form('submit', {
                url: url,
                onSubmit: function (param) {
                    var isValid = $(this).form('validate');
                    if (!isValid) {
                        layer.close(index);
                        layer.msg("请正确填写表单")
                    }

                    param["rehearsalUser"] = JSON.stringify($('#user_table').datagrid('getRows'));
                    return $(this).form('validate');
                },
                success: function (result) {
                    var data = $.parseJSON(result);
                    successCallback(data)
                }
            });
        });

    });
}
